<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*  var t1 = new Date();
      console.log(t1);
      /*
         var t2 =new Date ('2020-08-26')
         var t3 =new Date ('2020/08/26')
         console.log(t2)
         console.log(t3); */
      //年月日
      /*  console.log(t1.getFullYear()); //年 2020
      console.log(t1.getMonth() + 1); //月份  8  需要+1
      console.log(t1.getDate()); //日   26
      //时分秒
      console.log(t1.getHours()); //  15时
      console.log(t1.getMinutes()); //16分
      console.log(t1.getSeconds()); // 30秒
      //获取周几
      console.log(t1.getDay()); //周3    周0-6*/

      //字符拼接
      function add(t1) {
        //   var t1 = new Date();

        var yy = t1.getFullYear();
        var mm = t1.getMonth() + 1;
        var ri = t1.getDate();
        var h = t1.getHours();
        var m = t1.getMinutes();
        var s = t1.getSeconds();

        //如果月 日时分 秒 小于10 我们需要在前面加个0
        mm = mm < 10 ? '0' + mm : mm;
        ri = ri < 10 ? '0' + ri : ri;
        h = h < 10 ? '0' + h : h;
        m = m < 10 ? '0' + m : m;
        s = s < 10 ? '0' + s : s;

        return yy + '年' + mm + '月' + ri + '日' + h + '时' + m + '分' + s + '秒';
      }
      var tt = add(new Date());
      console.log(tt);
    </script>
  </body>
  w
</html>
